package com.lhl.jwt.controller;

import com.lhl.jwt.domain.entity.SysUser;
import com.lhl.jwt.repository.UserRepository;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @className: com.lhl.security.jwt.controller.AuthController
 * @description: TODO 类描述
 * @author: king
 * @date: 2020-11-09
 **/
@Api(tags = "AuthController", produces = "")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private UserRepository userRepository;

    @PostMapping("/register")
    public String registerUser(@RequestBody Map<String,String> registerUser){
        SysUser user = new SysUser();
        user.setUsername(registerUser.get("username"));
        user.setPassword(new BCryptPasswordEncoder().encode(registerUser.get("password")));
        user.setRole(registerUser.get("role"));
        user.setMobile(registerUser.get("mobile"));
        userRepository.save(user);
        return "success";
    }
}
